package task_calculator

type TaskCalculator struct {
	TaskCount int
	lastIndex int64
}

func NewTaskCalculator(benchmark int) *TaskCalculator {
	taskCalculator := TaskCalculator{}
	taskCalculator.TaskCount = taskCalculator.computeCount(benchmark)
	taskCalculator.lastIndex = int64(taskCalculator.TaskCount - 1)
	return &taskCalculator
}

func (this *TaskCalculator) computeCount(benchmark int) int {
	count := 1
	if benchmark <= 1 {
		return count
	}
	for {
		if count >= benchmark {
			break
		}
		count = count << 1
	}
	return count
}

func (this *TaskCalculator) ComputeIndex(number int64) int64 {
	return this.lastIndex & number
}
